package com.hongxun.design.acceptance.fragments;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.hongxun.design.MyApp;
import com.hongxun.design.R;
import com.hongxun.design.acceptance.adapter.PAFLvAdapter;
import com.hongxun.design.acceptance.mode.ProblemR;
import com.hongxun.design.acceptance.mode.problemExist;
import com.hongxun.design.bean.Exploration;
import com.hongxun.design.fragments.BaseFragment;
import com.hongxun.design.utils.fileutil.GetFileUtil;
import com.hongxun.design.utils.projectdatautil.DataFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by cqcqwu 问题汇总
 */

public class ProjectAcceptFragment extends BaseFragment {
    private List<problemExist> existList;
    private ListView listView;
    private PAFLvAdapter adapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_pro_acc, container, false);
        findViewByid(view);
        return view;
    }

    private void findViewByid(View view) {
        listView = (ListView) view.findViewById(R.id.paf_lv);

        existList = new ArrayList<>();
        adapter = new PAFLvAdapter(getActivity(), existList);
        listView.setAdapter(adapter);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
    }

    private void initData() {
        List<Exploration> explorations = GetFileUtil.getExplorationList("11");
        List<ProblemR> rList = DataFactory.getProblemRs(getActivity().getApplicationContext());
        List<problemExist> list = DataFactory.getExPro(getActivity().getApplicationContext());
        for (problemExist exist : list) {
            if (exist.getProjectId().equals(MyApp.currProject.getStage_id())) {
                for (Exploration exploration : explorations) {
                    if (exist.getPointId().equals(exploration.getExploration_id())) {
                        String pointType = "";
                        for (ProblemR problemR : rList) {
                            if (problemR.getTermCode().equals(exploration.getPt_id())) {
                                pointType = problemR.getTermName();
                                break;
                            }
                        }
                        String wz = pointType + exploration.getNumber() + "#";
                        exist.setNote(wz);
                        existList.add(exist);
                        break;
                    }
                }
            }
        }
        if (!existList.isEmpty()) adapter.notifyDataSetChanged();
    }
}
